﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Windows.Forms;

namespace ChimneySim
{
    class Chimney
    {
        public BoundingBox chimneyLeft, chimneyRight, chimneyFront, chimneyBack;
        public BoundingBox chimneyAll;
        private World world;
        private Room room;
        private MainForm form;
        
        public Chimney(MainForm form, World world, Room room)
        {
            this.form = form;
            this.world = world;
            this.room = room;
        }

        public void Refresh()
        {
            chimneyAll = new BoundingBox(chimneyRight.Min, chimneyLeft.Max);
        }

        public float TemperatureOnHeight(float height)
        {
            float a = -(room.TemperatureOnHeight(0) - world.TemperatureOnHeight(chimneyLeft.Max.Y)) / (chimneyLeft.Max.Y * chimneyLeft.Max.Y);
            float c = room.TemperatureOnHeight(0);

            return a * height * height + c;
        }

        public float RoOnHeight(float height)
        {
            return world.pressure / ((float)8.3144 * TemperatureOnHeight(height));
        }

        public float ActivePressureOnHeight(float height)
        {
            return (RoOnHeight(chimneyLeft.Max.Y) - RoOnHeight(height)) * chimneyLeft.Max.Y * world.gravity;
        }

        public float ActiveForceOnHeight(float height)
        {
            float S = Math.Abs(chimneyRight.Min.X - chimneyLeft.Max.X) * Math.Abs(chimneyLeft.Max.Z - chimneyRight.Min.Z);

            return ActivePressureOnHeight(height) * S;
        }
    }
}
